home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17353 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.magmacom.com!not-for-mail
  2. From: ezust@mag1.magmacom.com (Acme Instant Dehydrated Boulder Kit)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ complex numbers slow as molasses?
  5. Date: 15 Apr 1996 09:56:23 -0400
  6. Organization: Cloud-Zero, Canada
  7. Message-ID: <4ktki7$vft@mag1.magmacom.com>
  8. References: <4k6k8c$8h4@nyx.cs.du.edu> <9604071851.AA001o1@lorelei.demon.co.uk> <4ke5ap$b8b@mag1.magmacom.com> <Pine.LNX.3.91.960412073943.308E-100000@quoin1.quoininc.com>
  9. NNTP-Posting-Host: mag1.magmacom.com
  10.  
  11. In article <Pine.LNX.3.91.960412073943.308E-100000@quoin1.quoininc.com>,
  12. Jean Pierre LeJacq  <jplejacq@quoininc.com> wrote:
  13. >
  14. >I agree with the basic idea but I prefer to distinguish member
  15. >functions as either referenced or value based.  OO languages are
  16.  
  17.  
  18. Thanks for pointing that out to me. I was not familiar with a term
  19. that would describe this phenomenon.
  20.  
  21.  
  22. >more efficient manipulating existing objects (referenced based)
  23. >than creating new one (value based).  Fortunately, C++ provides
  24. >both types of operators so it isn't necessary to define functions
  25. >like "add()".  Instead,
  26. >
  27. >class complex {
  28. >   public:
  29. >      complex & operator +=(complex const & lhs);
  30. >};
  31.  
  32. The choices are:
  33.  
  34. If you use the +=, you must first initialize the destination explicitly, and
  35. then call it twice to achieve the same functionality as one call to the
  36. binary operator+ 
  37.  
  38. Or, you can make one call to a 2-operand member function. Some people like
  39. using the += in place of the +, others would rather achieve some semantic
  40. which resembles the + operator. It's just a matter of personal taste, IMHO.
  41.  
  42. But if one is really concerned about runtime efficiency, chances are that a
  43. 2-operand member function add can be written so it is more efficient than
  44. the operator+= used in the way described above.
  45.  
  46.  
  47. -- 
  48. Alan Ezust                       "Just because I work for the federal
  49. Ottawa, Canada                    government doesn't mean I'm an expert
  50. ezust@magmacom.com                on cockroaches"  -Special Agent Fox Mulder
  51. http://www2.magmacom.com/~ezust   
  52.